﻿using System;
using System.Windows;
using MSUS.Kinect.PowerPointController;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using System.Reflection;
using System.IO;

namespace MSUS.Kinect.PowerPointAddIn
{
    public partial class ThisAddIn
    {
        private MainWindow _kinectTrackingWindow;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Application.SlideShowBegin += ApplicationSlideShowBegin;
            Application.SlideShowEnd += ApplicationSlideShowEnd;
        }

        void ApplicationSlideShowEnd(PowerPoint.Presentation presentation)
        {
            if (_kinectTrackingWindow != null)
                _kinectTrackingWindow.Hide();
        }

        void ApplicationSlideShowBegin(PowerPoint.SlideShowWindow slideShowWindow)
        {
            try
            {
                if (Globals.Ribbons.KinectRibbon.KinectControlEnabled)
                {
                    if (_kinectTrackingWindow == null)
                        _kinectTrackingWindow = new MainWindow(Application);

                    _kinectTrackingWindow.Show();
                }
            }
            catch (NoActiveKinectException)
            {
                MessageBox.Show(
                    "No Kinect was detected.\n\nMake sure that the Kinect and Kinect SDK are installed corretly.",
                    "Kinect detection error",
                    MessageBoxButton.OK);
                return;
            }
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}
